package cn.edu.njust.epms.config;

import cn.edu.njust.epms.interceptor.LoginInterceptor;
import cn.edu.njust.epms.interceptor.UserInterceptor;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 配置类
 */
@Configuration
public class WebMvcConfiguration implements WebMvcConfigurer {


    @Override
    public void addInterceptors(InterceptorRegistry registry){
        registry.addInterceptor(new LoginInterceptor()).addPathPatterns("/**").excludePathPatterns("/login","/code","/reg","/logout");
        //对所有用户放行：登陆注册，其余全部拦截
        //针对下载等功能，只对管理员开放
        registry.addInterceptor(new UserInterceptor()).addPathPatterns("/AcidTest/list/download","/AcidTest/resv/list/download"
                ,"/HealthReport/list/download","/io/reg","/io/download","/item/audit"
                ,"/item/download","/aud_apply","/HealthReport/list/delete","/HealthReport/list/not_report","/AcidTest/list/not_at");
    }
}
